package lt.ntec.sudokusolver.engine;

import java.util.ArrayList;

public class Cell {
	private int number;

	private Group group;
	private Row row;
	private Column column;

	public Cell(int number, Group group, Row row, Column column) {
		super();
		this.number = number;
		this.group = group;
		this.row = row;
		this.column = column;
	}

	public int getNumber() {
		return number;
	}

	public Group getGroup() {
		return group;
	}

	public Row getRow() {
		return row;
	}

	public Column getColumn() {
		return column;
	}

	public void setNumber(int number) {
		if (number < 0 || number > 9) {
			throw new RuntimeException("Number out of bounds");
		}

		this.number = number;
	}

	public ArrayList<Integer> getPossibleValues() {
		ArrayList<Integer> nums = new ArrayList<Integer>();

		if (number != 0) {
			nums.add(number);
			return nums;
		}

		for (int i = 1; i <= 9; i++) {
			nums.add(new Integer(i));
		}

		for (CellContainer con : getContainers()) {
			for (Cell cell : con.getCells()) {
				Integer m = new Integer(cell.getNumber());
				if (nums.contains(m)) {
					nums.remove(m);
				}
			}
		}

		return nums;
	}

	protected ArrayList<CellContainer> getContainers() {
		ArrayList<CellContainer> con = new ArrayList<CellContainer>();
		con.add(column);
		con.add(group);
		con.add(row);
		return con;
	}

}
